<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <div class="row">
             <div class="col-sm-12 search-collapse">
                 <form id="role-form">
                     <input type="hidden" id="sId" name="sId" th:value="${student.id}">
                 </form>
             </div>

             <div class="btn-group-sm" id="toolbar" role="group">
                 <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:course:add">
                     <i class="fa fa-plus"></i> 添加
                 </a>
                 <a class="btn btn-warning" onclick="closeItem()">
                     <i class="fa fa-reply-all"></i> 关闭
                 </a>
             </div>

             <div class="col-sm-12 select-table table-striped">
                 <table id="bootstrap-table"></table>
             </div>
         </div>
     </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:course:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:course:remove')}]];
        var courseIdDatas = [[${@dict.getType('sys_course')}]];
        var cTypeIdDatas = [[${@dict.getType('sys_course_type')}]];
        var pIdDatas = [[${@dict.getType('sys_professional')}]];
        var prefix = ctx + "system/course";

        var data = "";
        $(function() {

            $.operate.post(ctx + "system/choose/list",data,function (result) {
                console.log(result);
                data = result.rows;
            });
            var options = {
                url:  ctx + "system/student/selectCourseBySid/"+$("#sId").val(),
                createUrl: prefix + "/add/"+$("#sId").val(),
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "课程管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'courseId',
                    title: '课程',
                    formatter: function(value, row, index) {
                        for (var i = 0; i < data.length; i++) {
                            if(value === data[i].courseId){
                                return data[i].courseName;
                            }
                        }
                    }
                },
                {
                    field: 'cTypeId',
                    title: '课程类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(cTypeIdDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="deleteById(\'' + row.courseId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 删除*/
        function deleteById(courseId) {
            $.modal.confirm("确认要删除该学生课程吗？", function() {
                $.operate.post(prefix + "/deleteById", { "courseId": courseId, "sId": $("#sId").val() });
            })
        }
    </script>
</body>
</html>
